package com.yf.course.modules.course.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.yf.base.api.api.ApiRest;
import com.yf.base.api.api.controller.BaseController;
import com.yf.base.api.api.dto.PagingReqDTO;
import com.yf.course.modules.course.dto.CourseFaceCaptureDTO;
import com.yf.course.modules.course.dto.CourseFaceRecordDTO;
import com.yf.course.modules.course.dto.request.CourseFaceCaptureReqDTO;
import com.yf.course.modules.course.dto.request.CourseFaceSaveReqDTO;
import com.yf.course.modules.course.dto.response.CaptureRespDTO;
import com.yf.course.modules.course.service.CourseFaceCaptureService;
import com.yf.course.modules.course.service.CourseFaceRecordService;
import com.yf.system.modules.user.dto.response.FaceCheckRespDTO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
* <p>
* 学习截屏记录控制器
* </p>
*
* @author 聪明笨狗
* @since 2022-04-25 10:35
*/
@Api(tags={"学习截屏记录"})
@RestController
@RequestMapping("/api/course/face")
public class CourseFaceController extends BaseController {

    @Autowired
    private CourseFaceCaptureService baseService;

    @Autowired
    private CourseFaceRecordService courseFaceRecordService;

    /**
    * 添加或修改
    * @param reqDTO
    * @return
    */
    @ApiOperation(value = "添加或修改")
    @PostMapping("/save")
    public ApiRest<CaptureRespDTO> save(@RequestBody CourseFaceCaptureReqDTO reqDTO) {
        CaptureRespDTO respDTO = baseService.save(reqDTO);
        return super.success(respDTO);
    }


    /**
     * 保存人脸校验数据
     * @param reqDTO
     * @return
     */
    @ApiOperation(value = "课程人脸识别")
    @PostMapping("/face-check")
    public ApiRest<FaceCheckRespDTO> checkFace(@RequestBody CourseFaceSaveReqDTO reqDTO) {
        FaceCheckRespDTO respDTO = courseFaceRecordService.checkFace(reqDTO);
        return super.success(respDTO);
    }

    /**
     * 校验人脸是否超时
     * @param reqDTO
     * @return
     */
    @ApiOperation(value = "验证人脸是否识别")
    @PostMapping("/validate-face")
    public ApiRest<Boolean> check(@RequestBody CourseFaceRecordDTO reqDTO) {
        Boolean check = courseFaceRecordService.check(reqDTO);
        return super.success(check);
    }


    /**
     * 刷脸记录列表
     * @param reqDTO
     * @return
     */
    @ApiOperation(value = "刷脸记录列表")
    @RequiresPermissions("course:list")
    @PostMapping("/face-paging")
    public ApiRest<IPage<CourseFaceRecordDTO>> checkPaging(@RequestBody PagingReqDTO<CourseFaceRecordDTO> reqDTO) {
        //分页查询并转换
        IPage<CourseFaceRecordDTO> page = courseFaceRecordService.paging(reqDTO);
        return super.success(page);
    }

    /**
     * 刷脸记录列表
     * @param reqDTO
     * @return
     */
    @ApiOperation(value = "学习过程截屏记录")
    @RequiresPermissions("course:list")
    @PostMapping("/capture-paging")
    public ApiRest<IPage<CourseFaceCaptureDTO>> capturePaging(@RequestBody PagingReqDTO<CourseFaceCaptureDTO> reqDTO) {
        //分页查询并转换
        IPage<CourseFaceCaptureDTO> page = baseService.paging(reqDTO);
        return super.success(page);
    }
}
